<?php
namespace app\admin\controller;

/**
 * Class User
 * @package app\admin\controller
 * @property \app\admin\service\User $service
 */
class User extends Admin
{

	protected $noNeedLogin = [];
	protected $noNeedAuth = ['*'];

	public function index()
	{
		if ( $this->request->isAjax()){
			if($this->request->has('keyword','post')){
				$keyword = $this->request->post('keyword');
				$where = [
					['account','like',"%{$keyword}%"],
					['mobile','like',"%{$keyword}%"],
					['email','like',"%{$keyword}%"],
					['nickname','like',"%{$keyword}%"]
				];
			}else{
				$where = [];
			}
			return $this->service->getTableList($where);
		}
		return $this->fetch();
	}
	
	public function create()
	{
		if ( $this->request->isPost() ){
			return $this->service->create();
		}
		return $this->fetch();
	}
	
	public function update($id=null)
	{
		if ( $this->request->isPost() ){
			$this->service->update();
		}
		
		$info = $this->service->getModel()->find($id);
		$this->assign('info', $info);
		return $this->fetch();
	}
	
	public function delete(){
		return $this->service->delete();
	}

	public function toAuth(){
		if($this->request->isPost()){
			return $this->service->toAuth();
		}

		return $this->fetch();
	}
	
}
